﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace RoMBot.Classes
{
    [StructLayout( LayoutKind.Explicit, Pack = 1 )]
    public unsafe class BaseGameObject
    {
        public int NamePointer
        {
            get { return ( int ) NamePtr; }
        }

        public string Name
        {
            get
            {
                return Processname();
            }
        }

        private string Processname()
        {
            return NamePointer != 0 ? MemoryLib.Memory.ReadUtf8String( NamePointer ) : GameObject.UnknowName;
        }

        [FieldOffset( Addresses.pawnId_offset )]
        public int Id;

        [FieldOffset( Addresses.pawnName_offset )]
        public int* NamePtr;

        [FieldOffset( Addresses.pawnIsPet_offset )]
        public bool IsPet;

        [FieldOffset( Addresses.pawnLevel_offset )]
        public int Level;

        [FieldOffset( Addresses.pawnHP_offset )]
        public int HP;

        [FieldOffset( Addresses.pawnMaxHP_offset )]
        public int MaxHP;

        [FieldOffset( Addresses.pawnType_offset )]
        public ObjectType Type;

        [FieldOffset( Addresses.pawnAttackable_offset )]
        public int Attackable;

        [FieldOffset( Addresses.pawnTargetPtr_offset )]
        public int TargetPtr;

        [FieldOffset( Addresses.pawnGUID_offset )]
        public int GUID;

        [FieldOffset( 0 )]
        public BaseGameObjectLocation Location;

        public void Update()
        {
        }
    }

    [StructLayout( LayoutKind.Explicit, Pack = 1 )]
    public struct BaseGameObjectLocation
    {
        [FieldOffset( Addresses.pawnX_offset )]
        public float X;

        [FieldOffset( Addresses.pawnY_offset )]
        public float Y;

        [FieldOffset( Addresses.pawnZ_offset )]
        public float Z;

        public override string ToString()
        {
            return string.Format( "X: {0}, Y: {1}, Z: {2}", X, Y, Z );
        }
    }

    public class BaseName
    {
        public string name;
    }
}
